//
//  EFARptPreviewTCell.m
//  efairy
//
//  Created by XiangDongMBP on 2017/8/6.
//  Copyright © 2017年 East. All rights reserved.
//

#import "EFARptPreviewTCell.h"
#import "EFAModel.h"
#import <ZLYWaterWave.h>
#import "UIColor+XDHex.h"

@interface EFARptPreviewTCell ()<ZLYWaterWaveDelegate>
@property (strong, nonatomic) ZLYWaterWave *waterWave;
@property (nonatomic, strong) CAGradientLayer *gradientLayer;
@end

@implementation EFARptPreviewTCell
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    // 背景View
    self.ballBgView.layer.masksToBounds = YES;
    self.ballBgView.layer.cornerRadius = CGRectGetWidth(self.ballBgView.bounds) / 2.0;
    self.ballBgView.layer.borderWidth = 1;
    self.ballBgView.layer.borderColor = [UIColor xd_colorWithHex:0x53D9BE].CGColor;
    
    // 渐变色Layer
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.colors = @[(__bridge id)[UIColor xd_colorWithHex:0x32C8A8].CGColor,
                             (__bridge id)[UIColor xd_colorWithHex:0x8AF7DF].CGColor];
    gradientLayer.startPoint = CGPointMake(0.0, 0.0);
    gradientLayer.endPoint = CGPointMake(0.0, 1.0);
    gradientLayer.frame = self.ballInnerView.layer.bounds;
    self.gradientLayer = gradientLayer;
    [self.ballInnerView.layer addSublayer:gradientLayer];
    
    // 波浪
    self.waterWave = [[ZLYWaterWave alloc] initWithFrame:self.ballInnerView.frame];
    self.waterWave.amplitude = 5.0;
    self.waterWave.angularVelocity = 2.0;
    self.waterWave.waterDepth = 0.8;
    self.waterWave.delegate = self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - ZLYWaterWaveDelegate
- (void)waterWave:(ZLYWaterWave *)waterWave wavePath:(UIBezierPath *)path {
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.path = path.CGPath;
    // 添加覆盖
    self.ballInnerView.layer.mask = maskLayer;
}

- (void)startAnimation {
    [self.waterWave startAnimation];
}

- (void)stopAnimation {
    [self.waterWave stopAnimation];
}

- (void)configViewWithRptOverView:(EFARptOverView *)item {
    self.scoreLabel.text = [NSString stringWithFormat:@"%ld", (long)item.safely_points];
    if (item.safely_points < 60) {
        self.ballBgView.layer.borderColor = [UIColor xd_colorWithHex:0xFC9444].CGColor;
        self.ballBgView.backgroundColor = [UIColor xd_colorWithHex:0xFFF7EF];
        self.gradientLayer.colors = @[(__bridge id)[UIColor xd_colorWithHex:0xFF9444].CGColor,
                                      (__bridge id)[UIColor xd_colorWithHex:0xFFCFA1].CGColor];
    } else {
        self.ballBgView.layer.borderColor = [UIColor xd_colorWithHex:0x32C8A8].CGColor;
        self.ballBgView.backgroundColor = [UIColor xd_colorWithHex:0xE8FAF5];
        self.gradientLayer.colors = @[(__bridge id)[UIColor xd_colorWithHex:0x32C8A8].CGColor,
                                      (__bridge id)[UIColor xd_colorWithHex:0x8AF7DF].CGColor];
    }
}

@end
